package com.sunk.javaagent;

import com.sun.tools.attach.AttachNotSupportedException;
import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor;

import java.io.IOException;
import java.util.List;

/**
 * @Author: Sunk
 * @Date: 2020/10/22 14:28
 */
public class JvmAttach {

    public static void main(String[] args) throws IOException, AttachNotSupportedException {
        List<VirtualMachineDescriptor> list = VirtualMachine.list();
        for (VirtualMachineDescriptor virtualMachineDescriptor : list) {
            //PID
            System.out.println(virtualMachineDescriptor.id());
            VirtualMachine vm = VirtualMachine.attach(virtualMachineDescriptor.id());
            System.out.println(vm.getSystemProperties());
            vm.detach();
        }
    }

}
